package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.stream.Collector;

//泛型的演示
public class GenericDemo {
    public static void main(String[] args) {
        Collection<point>c=new ArrayList<>();
        c.add(new point(1,2));
        c.add(new point(3,4));
        c.add(new point(5,6));
        c.add(new point(7,8));
        Iterator<point> i=c.iterator();
        while (i.hasNext()){
            point p=i.next();
            System.out.println(p);

        }
        for (Object p:c){//p是变量 c是集合对应上面的
            System.out.println(p);

        }
























//        Collection<String> C= new ArrayList<>();//泛型集合
//        C.add("one");
//        C.add("two");
//        C.add("three");
//        C.add("five");
//        C.add("four");
//        //c.add(123)编译错误，123的类型违背了集合c所指向的泛型的实际型string
//        Iterator<String>it=C.iterator();
//        while (it.hasNext()){
//            String str=it.next();
//            System.out.println(str);
//        }
//        for (Object str:C){
//            System.out.println(str);
//
//        }
    }
}
